package 尚硅谷.juc.test13;

import lombok.extern.slf4j.Slf4j;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

@Slf4j
public class Test13 {

    /**
     * SynchronousQueue：
     */
    public static void main(String[] args) throws InterruptedException {
       BlockingQueue<String> blockingQueue=new SynchronousQueue<>();

       new Thread(()->{
           try {
               System.out.println("---A---");
               blockingQueue.put("A");
               System.out.println("---B---");
               blockingQueue.put("B");
               System.out.println("---C---");
               blockingQueue.put("C");
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       },"A").start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(5);
                blockingQueue.take();
                TimeUnit.SECONDS.sleep(5);
                blockingQueue.take();
                TimeUnit.SECONDS.sleep(5);
                blockingQueue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"B").start();
    }
}
